﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DoubanApiLib.OAuth;

namespace ApiTest
{
    /// <summary>
    /// OAuth认证模块
    /// </summary>
    public static class OAuthModule
    {

        /// <summary>
        /// 测试
        /// </summary>
        public static void Test()
        {
            string url, uid, acc, accsect;
            OAuthWork work = new OAuthWork();
            url = work.GetUserAuthorizationUrl();
            System.Diagnostics.Process.Start(url);
            Console.WriteLine("请在弹出的窗体内进行授权操作！授权完成后按任意键！");
            Console.ReadKey();

            if (work.GetAccountAccessToken(out uid, out acc, out accsect))
            {
                Console.WriteLine("ID为{0}的用户授权成功！accessToken={1}，accessTokenSecret={2}；", uid, acc, accsect);
            }
            else
            {
                Console.WriteLine("授权失败！");
            }
            Console.WriteLine("按任意键退出！");
            Console.ReadKey();
        }

        /// <summary>
        /// 测试
        /// </summary>
        public static void Test(out string acc,out string accsect)
        {
            string url, uid;
            OAuthWork work = new OAuthWork();
            url = work.GetUserAuthorizationUrl();
            System.Diagnostics.Process.Start(url);
            Console.WriteLine("请在弹出的窗体内进行授权操作！授权完成后按任意键！");
            Console.ReadKey();

            if (work.GetAccountAccessToken(out uid, out acc, out accsect))
            {
                Console.WriteLine("ID为{0}的用户授权成功！accessToken={1}，accessTokenSecret={2}；", uid, acc, accsect);
            }
            else
            {
                Console.WriteLine("授权失败！");
            }
            Console.WriteLine("按任意键退出！");
            Console.ReadKey();
        }
        /// <summary>
        /// 测试(返回成功授权后的UID)
        /// </summary>
        public static string TestReturnUid()
        {
            string url, uid, acc, accsect;
            OAuthWork work = new OAuthWork();
            url = work.GetUserAuthorizationUrl();
            System.Diagnostics.Process.Start(url);
            Console.WriteLine("请在弹出的窗体内进行授权操作！授权完成后按任意键！");
            Console.ReadKey();

            if (work.GetAccountAccessToken(out uid, out acc, out accsect))
            {
                Console.WriteLine("ID为{0}的用户授权成功！accessToken={1}，accessTokenSecret={2}；", uid, acc, accsect);
            }
            return uid;
        }
    }
}
